﻿/****************************** Module Header ******************************\
 * Module Name:  EmailHelper.cs
 * Module Version:  1.0.0 (2011-12-14)
 * Copyright (c) AnyEB.Com (14507247@qq.com)
 * 
 * This class is used to process email string.
 * 
 * This source is subject to the GPL License.
 * See http://www.gnu.org/licenses/gpl.html.
 * All other rights reserved.
 * 
 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/

using System;
using System.Collections.Generic;

namespace UCF.Core
{
    /// <summary>
    /// 电子邮件帮助类
    /// </summary>
    public class EmailStringHelper
    {
        /// <summary>
        /// 要操作的邮件地址
        /// </summary>
        private string email;

        /// <summary>
        /// 特殊域名的公开字段
        /// </summary>
        public Dictionary<string, string> SpecialDomain;

        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="email"></param>
        public EmailStringHelper(string email)
        {
            this.email = email;
            this.SpecialDomain = new Dictionary<string, string>() 
            { 
                { "hotmail.com", "www.hotmail.com" }, 
                { "gmail.com", "www.gmail.com" }, 
                { "vip.163.com", "vip.163.com" } 
            };
        }
        /// <summary>
        /// 静态构造方法
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public static implicit operator EmailStringHelper(string email)
        {
            return new EmailStringHelper(email);
        }
        /// <summary>
        /// 获取指定邮件地址的登录入口
        /// </summary>
        /// <returns></returns>
        public string GetLoginDomain(string email)
        {
            int intPos = this.email.IndexOf('@');
            if (intPos == -1) return email;
            string strDomain = email.Substring(intPos+1);
            if (this.SpecialDomain.ContainsKey(strDomain)) return this.SpecialDomain[strDomain];
            return string.Format("mail.{0}", strDomain);            
        }
        /// <summary>
        /// 获取指定邮件地址的登录入口
        /// </summary>
        /// <returns></returns>
        public string GetLoginDomain()
        {
            return this.GetLoginDomain(this.email);
        }
    }
}
